<template>
  <div style="background: #FFFFFF;padding: 20px 10px 10px 10px">
    <!--查询区域-->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <a-form-item label="车间">
              <j-dict-select-tag
                  placeholder="请选择车间"
                  v-model="queryParam.workshop"
                  dictCode="workshop"
                  @change="loadData(1)" />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="品种">
              <j-input placeholder="请输入品种" v-model="queryParam.productType" @change="loadData(1)" />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="时间">
              <j-date
                  v-model="queryParam.createTime"
                  :trigger-change="true"
                  date-format="YYYY-MM-DD 00:00:00"
                  style="width:100%"
                  placeholder="请选择时间">
              </j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="4" :md="4" :sm="24">
            <div style="display: flex; justify-content: flex-end">
              <a-button type="primary" @click="handleAdd">新增计划</a-button>
              <a-button type="primary" style="margin-left: 8px" @click="batchDel">批量删除</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--表格区域-->
    <div>
      <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap common-table"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <XiShaModal ref="modalForm" @ok="modalFormOk" :createTime="queryParam.createTime" :workingProcedure="workingProcedure"></XiShaModal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JInput from '@/components/jeecg/JInput'
import JDate from '@comp/jeecg/JDate'
import moment from 'moment'
import { getAction } from '@api/manage'
import XiShaModal from './XiShaModal'

export default {
  props: {
    workingProcedure: {
      type: String,
      require: true
    }
  },
  mixins: [JeecgListMixin],
  components: {
    JDate,
    JInput,
    JDictSelectTag,
    XiShaModal
  },
  data() {
    return {
      queryParam: {
        // createTime:moment().format("YYYY-MM-DD 00:00:00"),
        createTime: '2023-02-25 00:00:00',
        procedureCategory: 1,
        workshop: 5
      },
      columns: [
        {
          title: '车间',
          dataIndex: 'workshop_dictText',
          align: 'center'
        },
        {
          title: '楼层',
          dataIndex: 'floor_dictText',
          align: 'center'
        },
        {
          title: '品种',
          align: 'center',
          children: [
            {
              title: '品名',
              dataIndex: 'productType_dictText',
              align: 'center'
            },
            {
              title: '批号',
              dataIndex: 'productBatch',
              align: 'center'
            },
            {
              title: '支别',
              dataIndex: 'productBranch',
              align: 'center'
            }
          ]
        },
        {
          title: '设计参数',
          align: 'center',
          children: [
            {
              title: '车速',
              dataIndex: 'speed',
              align: 'center'
            },
            {
              title: '产量(台/24小时)',
              dataIndex: 'output',
              align: 'center'
            }
          ]
        },
        {
          title: '日开台情况',
          align: 'center',
          children: [
            {
              title: '计划台数',
              dataIndex: 'planOpen',
              align: 'center'
            },
            {
              title: '计划停台',
              dataIndex: 'planStop',
              align: 'center'
            },
            {
              title: '实际开台',
              dataIndex: 'actualOpen',
              align: 'center'
            },
            {
              title: '开台产量',
              dataIndex: 'openOutput',
              align: 'center'
            },
            {
              title: '车速对比',
              dataIndex: 'speedComparison',
              align: 'center'
            },
            {
              title: '入库数量',
              dataIndex: 'inQuantity',
              align: 'center'
            }
          ]
        },
        {
          title: '开台数/班',
          align: 'center',
          children: [
            {
              title:'24小时（A班）',
              align: 'center',
            }
          ]
        },
        {
          title: '开台产量/班',
          align: 'center',
          children: [
            {
              title:'24小时（A班）',
              align: 'center',
            }
          ]
        },
        {
          title: '设计定额长度（百米/台/12小时）',
          dataIndex: 'quotaLength',
          align: 'center'
        },
        {
          title: '机台号',
          dataIndex:'openInfos',
          align: 'center',
         children: [
           {
             title:'24小时（A班）',
             align: 'center',
           }
         ]
        },
        {
          title: '品种代号',
          dataIndex: 'productCode',
          align: 'center'
        },
        {
          title: '标准定额',
          align: 'center',
          children: [
            {
              title: '全称',
              dataIndex: 'productFullName',
              align: 'center'
            },
            {
              title: '锭数',
              dataIndex: 'standardIngot',
              align: 'center'
            },
            {
              title: '定量',
              dataIndex: 'standardRation',
              align: 'center'
            },
            {
              title: '车速',
              dataIndex: 'standardSpeed',
              align: 'center'
            },
            {
              title: '效率',
              dataIndex: 'standardEfficiency',
              align: 'center'
            },
            {
              title: '产量（台/24小时）',
              dataIndex: 'standardOutput',
              align: 'center'
            },
            {
              title: '长度（百米/台/24小时）',
              dataIndex: 'standardLength',
              align: 'center'
            },
            {
              title: '班用工数',
              dataIndex: 'employees',
              align: 'center'
            },
            {
              title: '细纱管颜色',
              dataIndex: 'spunYarnTubeColor',
              align: 'center'
            }
          ]
        },
        {
          title: '入库数量与开台产量对比',
          dataIndex: 'inQuantityAnOutPutComparison',
          align: 'center'
        },
        {
          title: '操作',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/crm_product_type/CrmDailyPlan/list', //查询列表
        delete: '/crm_product_type/CrmDailyPlan/delete', //删除记录
        deleteBatch: '/crm_product_type/CrmDailyPlan/deleteBatch', //批量删除
        exportXlsUrl: '/crm_personnel/crmPersonnel/exportXls', //导出excel
        importExcelUrl: '/crm_personnel/crmPersonnel/importExcel', //导入excel
        exportTemplateXlsUrl: '/crm_personnel/crmPersonnel/exportTemplateXls', //导出模板excel
        shiftList: '/crm_shift/crmShift/list' //轮班管理
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件
      this.loading = true

      getAction(this.url.shiftList, {
        workshop: this.queryParam.workshop,
        workingProcedure: this.workingProcedure,
        startTime: moment(this.queryParam.createTime).format('YYYY-MM-DD')
      }).then(res => {
        if (res.success) {
          const shiftType = Number(res.result.records[0].shiftType);
          let children1 = [];
          let children2 = [];
          let children3 = [];
          switch (shiftType) {
            case 0:
              return;
            case 1:
              children1 = [
                {
                  title: `24小时（A班）`,
                  dataIndex: 'openInfos[0]["openNum"]',
                  align: 'center'
                },
              ]
              children2 = [
                {
                  title: `24小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
              ]
              children3 = [
                {
                  title: `24小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
              ]
              break
            case 2:
              children1 = [
                {
                  title: `12小时（A班）`,
                  dataIndex: 'openInfos[0]["openNum"]',
                  align: 'center'
                },
                {
                  title: `12小时（B班）`,
                  dataIndex: 'openInfos[1]["openNum"]',
                  align: 'center'
                },
              ]
              children2 = [
                {
                  title: `12小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
                {
                  title: `12小时（B班）`,
                  dataIndex: 'openInfos[1]["outPut"]',
                  align: 'center'
                },
              ]
              children3 = [
                {
                  title: `12小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
                {
                  title: `12小时（B班）`,
                  dataIndex: 'openInfos[1]["outPut"]',
                  align: 'center'
                },
              ]
              break
            case 3:
              children1 = [
                {
                  title: `8小时（A班）`,
                  dataIndex: 'openInfos[0]["openNum"]',
                  align: 'center'
                },
                {
                  title: `8小时（B班）`,
                  dataIndex: 'openInfos[1]["openNum"]',
                  align: 'center'
                },
                {
                  title: `8小时（C班）`,
                  dataIndex: 'openInfos[2]["openNum"]',
                  align: 'center'
                }
              ]
              children2 = [
                {
                  title: `8小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
                {
                  title: `8小时（B班）`,
                  dataIndex: 'openInfos[1]["outPut"]',
                  align: 'center'
                },
                {
                  title: `8小时（C班）`,
                  dataIndex: 'openInfos[2]["outPut"]',
                  align: 'center'
                },
              ]
              children3 = [
                {
                  title: `8小时（A班）`,
                  dataIndex: 'openInfos[0]["outPut"]',
                  align: 'center'
                },
                {
                  title: `8小时（B班）`,
                  dataIndex: 'openInfos[1]["outPut"]',
                  align: 'center'
                },
                {
                  title: `8小时（C班）`,
                  dataIndex: 'openInfos[2]["outPut"]',
                  align: 'center'
                },
              ]
              break
          }
          this.$set(this.columns[5], 'children', children1);
          this.$set(this.columns[6], 'children', children2);
          this.$set(this.columns[8], 'children', children3);
          console.log(shiftType,children1,children2,this.columns)
          getAction(this.url.list, params).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.ipagination.total = res.result.total
              } else {
                this.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          }).finally(() => {
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })


    },
  }
}
</script>

